package cn.signalpha.modules.pay.config;

import cn.signalpha.common.cache.ConfigKeys;
import cn.signalpha.common.dto.ConfigDTO;
import cn.signalpha.core.tool.jackson.JsonUtil;
import cn.signalpha.modules.system.service.IConfigService;
import com.ijpay.wxpay.WxPayApiConfig;
import com.ijpay.wxpay.WxPayApiConfigKit;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 支付配置
 *
 * @author signalpha
 */
@Configuration
@AllArgsConstructor
public class PayConfiguration {

	private static final String appId = "OP00000003"; // 拉卡拉appId

	private static final String serialNo = "00dfba8194c41b84cf"; // 你的证书序列号
	/**
	 * 商户私钥信息
	 */
	private static final String priKeyStr = "-----BEGIN PRIVATE KEY-----\n" +
		"MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDvDBZyHUDndAGx\n" +
		"rIcsCV2njhNO3vCEZotTaWYSYwtDvkcAb1EjsBFabXZaKigpqFXk5XXNI3NIHP9M\n" +
		"8XKzIgGvc65NpLAfRjVql8JiTvLyYd1gIUcOXMInabu+oX7dQSI1mS8XzqaoVRhD\n" +
		"ZQWhXcJW9bxMulgnzvk0Ggw07AjGF7si+hP/Va8SJmN7EJwfQq6TpSxR+WdIHpbW\n" +
		"dhZ+NHwitnQwAJTLBFvfk28INM39G7XOsXdVLfsooFdglVTOHpNuRiQAj9gShCCN\n" +
		"rpGsNQxDiJIxE43qRsNsRwigyo6DPJk/klgDJa417E2wgP8VrwiXparO4FMzOGK1\n" +
		"5quuoD7DAgMBAAECggEBANhmWOt1EAx3OBFf3f4/fEjylQgRSiqRqg8Ymw6KGuh4\n" +
		"mE4Md6eW/B6geUOmZjVP7nIIR1wte28M0REWgn8nid8LGf+v1sB5DmIwgAf+8G/7\n" +
		"qCwd8/VMg3aqgQtRp0ckb5OV2Mv0h2pbnltkWHR8LDIMwymyh5uCApbn/aTrCAZK\n" +
		"NXcPOyAn9tM8Bu3FHk3Pf24Er3SN+bnG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/bT5JfIi6jbg3EoE9YhB0+1aGAS1O2dBvUiD8tJ+BjAT4OB0UDpmM6\n" +
		"QsFLQgFyXgvDnzr/o+hQJelW\n" +
		"-----END PRIVATE KEY-----";
	/**
	 * 拉卡拉支付平台证书
	 */
	private static final String lklCerStr = "-----BEGIN CERTIFICATE-----\n" +
		"MIIEMTCCAxmgAwIBAgIGAXRTgcMnMA0GCSqGSIb3DQEBCwUAMHYxCzAJBgNVBAYT\n" +
		"AkNOMRAwDgYDVQQIDAdCZWlKaW5nMRAwDgYDVQQHDAdCZWlKaW5nMRcwFQYDVQQK\n" +
		"DA5MYWthbGEgQ28uLEx0ZDEqMCgGA1UEAwwhTGFrYWxhIE9yZ2FuaXphdGlvbiBW\n" +
		"YWxpZGF0aW9uIENBMB4XDTIwMTAxMDA1MjQxNFoXDTMwMTAwODA1MjQxNFowZTEL\n" +
		"MAkGA1UEBhMCQ04xEDAOBgNVBAgMB0JlaUppbmcxEDAOBgNVBAcMB0JlaUppbmcx\n" +
		"FzAVBgNVBAoMDkxha2FsYSBDby4sTHRkMRkwFwYDVQQDDBBBUElHVy5MQUtBTEEu\n" +
		"Q09NMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt1zHL54HiI8d2sLJ\n" +
		"lwoQji3/ln0nsvfZ/XVpOjuB+1YR6/0LdxEDMC/hxI6iH2Rm5MjwWz3dmN/6BZeI\n" +
		"gwGeTOWJUZFARo8UduKrlhC6gWMRpAiiGC8wA8stikc5gYB+UeFVZi/aJ0WN0cpP\n" +
		"JYCvPBhxhMvhVDnd4hNohnR1L7k0ypuWg0YwGjC25FaNAEFBYP9EYUyCJjE//9Z7\n" +
		"sMzHR9SJYCqqo6r9bOH9G6sWKuEp+osuAh+kJIxJMHfipw7w3tEcWG0hce9u/el4\n" +
		"cYJtg8/PPMVoccKmeCzMvarr7jdKP4lenJbtwlgyfs+JgNu60KMUJH8RS72wC9NY\n" +
		"uFz09wIDAQABo4HVMIHSMIGSBgNVHSMEgYowgYeAFCnH4DkZPR6CZxRn/kIqVsMo\n" +
		"dJHpoWekZTBjMQswCQYDVQQGEwJDTjEQMA4GA1UECAwHQmVpSmluZzEQMA4GA1UE\n" +
		"BwwHQmVpSmluZzEXMBUGA1UECgwOTGFrYWxhIENvLixMdGQxFzAVBgNVBAMMDkxh\n" +
		"a2FsYSBSb290IENBggYBaiUALIowHQYDVR0OBBYEFJ2Kx9YZfmWpkKFnC33C0r5D\n" +
		"K3rFMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgeAMA0GCSqGSIb3DQEBCwUA\n" +
		"A4IBAQBZoeU0XyH9O0LGF9R+JyGwfU/O5amoB97VeM+5n9v2z8OCiIJ8eXVGKN9L\n" +
		"tl9QkpTEanYwK30KkpHcJP1xfVkhPi/cCMgfTWQ5eKYC7Zm16zk7n4CP6IIgZIqm\n" +
		"TVGsIGKk8RzWseyWPB3lfqMDR52V1tdA1S8lJ7a2Xnpt5M2jkDXoArl3SVSwCb4D\n" +
		"AmThYhak48M++fUJNYII9JBGRdRGbfJ2GSFdPXgesUL2CwlReQwbW4GZkYGOg9LK\n" +
		"CNPK6XShlNdvgPv0CCR08KCYRwC3HZ0y1F0NjaKzYdGNPrvOq9lA495ONZCvzYDo\n" +
		"gmsu/kd6eqxTs/JwdaIYr4sCMg8Z\n" +
		"-----END CERTIFICATE-----";
	/**
	 * 拉卡拉支付平台证书2(用于拉卡拉通知验签)
	 */
	private static final String lklNotifyCerStr = "-----BEGIN CERTIFICATE-----\n" +
		"MIIEMTCCAxmgAwIBAgIGAXRTgcMnMA0GCSqGSIb3DQEBCwUAMHYxCzAJBgNVBAYT\n" +
		"AkNOMRAwDgYDVQQIDAdCZWlKaW5nMRAwDgYDVQQHDAdCZWlKaW5nMRcwFQYDVQQK\n" +
		"DA5MYWthbGEgQ28uLEx0ZDEqMCgGA1UEAwwhTGFrYWxhIE9yZ2FuaXphdGlvbiBW\n" +
		"YWxpZGF0aW9uIENBMB4XD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cJP1xfVkhPi/cCMgfTWQ5eKYC7Zm16zk7n4CP6IIgZIqm\n" +
		"TVGsIGKk8RzWseyWPB3lfqMDR52V1tdA1S8lJ7a2Xnpt5M2jkDXoArl3SVSwCb4D\n" +
		"AmThYhak48M++fUJNYII9JBGRdRGbfJ2GSFdPXgesUL2CwlReQwbW4GZkYGOg9LK\n" +
		"CNPK6XShlNdvgPv0CCR08KCYRwC3HZ0y1F0NjaKzYdGNPrvOq9lA495ONZCvzYDo\n" +
		"gmsu/kd6eqxTs/JwdaIYr4sCMg8Z\n" +
		"-----END CERTIFICATE-----";
	/**
	 * 拉卡拉报文加密对称性密钥
	 */
	private static final String sm4Key = "uIj6CPg1GZAY10dXFfsEAQ==";
	/**
	 * 服务地址
	 */
	private static final String serverUrl = "https://test.wsmsd.cn/sit";

	private final IConfigService configService;

	@Bean
	public WxPayApiConfig wxPayConfig() {
		ConfigDTO.WxPayDTO wxPayDTO = JsonUtil.parse(configService.getValue(ConfigKeys.WX_PAY), ConfigDTO.WxPayDTO.class);
		WxPayApiConfig wxPayApiConfig = WxPayApiConfig.builder()
			.appId(wxPayDTO.getAppId())
			.mchId(wxPayDTO.getMchId())
			.apiKey(wxPayDTO.getApiKey2())
			.apiKey3(wxPayDTO.getApiKey3())
			.certPath(wxPayDTO.getCertPath())
			.keyPath(wxPayDTO.getKeyPath())
			.certP12Path(wxPayDTO.getCertP12Path())
			.platformCertPath(wxPayDTO.getPlatformCertPath())
			.exParams(wxPayDTO.getSerialNo())
			.build();
		WxPayApiConfigKit.putApiConfig(wxPayApiConfig);
		return wxPayApiConfig;
	}



//	@Bean
//	public AliPayApiConfig aliPayApiConfig() {
//		ConfigDTO.AliPayDTO aliPayDTO = JsonUtil.parse(configService.getValue(ConfigKeys.ALI_PAY), ConfigDTO.AliPayDTO.class);
//		AliPayApiConfig aliPayApiConfig = AliPayApiConfig.builder()
//			.setAppId(Func.toStrWithEmpty(aliPayDTO.getAppId(), "ali"))
//			.setPrivateKey(aliPayDTO.getPrivateKey())
//			.setAliPayPublicKey(aliPayDTO.getPublicKey())
//			.setAppCertPath("")
//			.setAliPayCertPath("")
//			.setAliPayRootCertPath("")
//			.setServiceUrl("https://openapi.alipay.com/gateway.do")
//			.setCharset("UTF-8")
//			.setSignType("RSA2")
//			// 普通公钥方式
//			.build();
//			// 证书模式
//			//.buildByCert();
//
//		AliPayApiConfigKit.setThreadLocalAppId(Func.toStrWithEmpty(aliPayDTO.getAppId(), "ali"));
//		AliPayApiConfigKit.setThreadLocalAliPayApiConfig(aliPayApiConfig);
//		return aliPayApiConfig;
//	}

//	@Bean
//	public void lklPayConfig() {
//		ConfigDTO.LklPayDTO lklPayDTO = JsonUtil.parse(configService.getValue(ConfigKeys.LKL_PAY), ConfigDTO.LklPayDTO.class);
//		Config2 config = new Config2();
//		config.setAppId(lklPayDTO.getAppId());
//		config.setSerialNo(lklPayDTO.getSerialNo());
//		config.setPriKey(lklPayDTO.getPriKey());
//		config.setLklCer(lklPayDTO.getLklCer());
//		config.setLklNotifyCer(lklPayDTO.getLklNotifyCer());
//		config.setServerUrl(lklPayDTO.getServerUrl());
//		config.setSm4Key(lklPayDTO.getSm4Key());
//		try {
//			LKLSDK.init(config);
//		} catch (SDKException e) {
//			e.printStackTrace();
//		}
//	}

}
